/**
 * 
 */
package de.peacei.android.ioex_notesapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

/**
 * @author Matthias
 *
 */
public class NoteActivity extends Activity {
    
    public static final String EXTRA_NOTE = "extraNote";
    
    private TextView textView;
    private EditText editText;
    private Button saveButton;
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_note);
        
        textView = (TextView) findViewById(R.id.textView);
        editText = (EditText) findViewById(R.id.editText);
        saveButton = (Button) findViewById(R.id.saveButton);
        
        Intent intent = getIntent();
        
        Bundle bundle = intent.getExtras();
        
        if((bundle != null) && (bundle.containsKey(EXTRA_NOTE))) {
            String note = bundle.getString(EXTRA_NOTE);
            
            textView.setText(note);
        } else {
            textView.setVisibility(View.GONE);
            editText.setVisibility(View.VISIBLE);
            saveButton.setVisibility(View.VISIBLE);
        }
        
    }
    
    public void onButtonClick(View view) {
        Intent data = new Intent();
        data.putExtra(EXTRA_NOTE, editText.getText().toString());
        setResult(RESULT_OK, data);
        finish();
    }

}
